package com.sit.controller;

import com.sit.entity.AddAthlete;
import com.sit.entity.AddTeam;
import com.sit.service.CtService;
import com.sit.vo.DataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class CtController {

    @Autowired
    private CtService ctService;

    @ResponseBody
    @RequestMapping("/ctlist")
    public DataVO ctlist(Integer page, Integer limit){
        return ctService.findData(page,limit);
    }

    @ResponseBody
    @PostMapping("/addTeam")
    public boolean addAthlete(AddTeam addTeam){
        return ctService.addTeam(addTeam);
    }

    @ResponseBody
    @PostMapping("/updateTeam")
    public boolean updateAthlete(AddTeam addTeam, @RequestParam("cnoA_new")String cnoA_new){
        return ctService.updateTeam(addTeam,cnoA_new);
    }

    @ResponseBody
    @PostMapping("/deleteTeam")
    public boolean deleteTeam(@RequestParam("tno")String tno,@RequestParam("cnoA")String cnoA){
        return ctService.deleteTeam(tno, cnoA);
    }

    @ResponseBody
    @RequestMapping("/searchTeam")
    public DataVO searchTeam(@RequestParam("tno")String tno,@RequestParam("cnA")String cnA, @RequestParam("page")Integer page,@RequestParam("limit")Integer limit){
        return ctService.search(tno, cnA, page, limit);
    }

    @ResponseBody
    @PostMapping("/editScoreT")
    public boolean editScoreT(@RequestParam("tno")String tno,@RequestParam("cnA")String cnoA,
                             @RequestParam("rank")Integer rank,@RequestParam("score")String score){
        return ctService.editScoreT(tno, cnoA, rank, score);
    }
}
